package com.goktech.olala.client.controller.index;

import com.goktech.olala.core.resp.RespCategoryVo;
import com.goktech.olala.core.service.IGoodCategoryService;
import com.goktech.olala.core.service.IGoodIndexService;
import com.goktech.olala.server.pojo.goods.Activity;
import com.goktech.olala.server.pojo.goods.Advert;
import com.goktech.olala.server.pojo.goods.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author sanming
 * @Classname IndexController
 * @Description 首站信息查询：1.热门头条、2.热门活动、3.轮播图、4.全部分类展示
 * @Date 2020/12/7 19:13
 * @Created by sanming
 */

@RestController
public class IndexController {

    @Autowired
    IGoodIndexService goodIndexService;

    @Autowired
    IGoodCategoryService goodCategoryService;

    /**
     * 输入http://ip/部署项目名
     * 重定向到http://ip/部署项目名/index/init.do
     * @return 返回ModelAndView对象
     */
    @RequestMapping("/")
    public ModelAndView init(){
        ModelAndView mav=new ModelAndView();
        //重定向到 http://ip/部署项目名/index/init.do
        mav.setViewName("redirect:/index/init.do");
        return mav;
    }

    /**
     * 热门头条、热门活动、轮播图、全部分类展示
     * @return 返回ModelAndView对象
     */
    @RequestMapping("/index/init.do")
    public ModelAndView index(){
        ModelAndView mav=new ModelAndView();
        //查询的热门头条
        List<Article> articles = goodIndexService.selectArticle();
        //查询的热门活动
        List<Activity> activities = goodIndexService.selectActivity();
        //查询的轮播图
        List<Advert> adverts = goodIndexService.selectAdvert();

        //热门头条List传到前端页面
        mav.addObject("articleVoList", articles);
        //热门活动List传到前端页面
        mav.addObject("indexActivities", activities);
        //轮播图List传到前端页面
        mav.addObject("ctmAdvers", adverts);
        //获取一级二级三级分类的List
        List<RespCategoryVo> respCategoryVos = goodCategoryService.beTreeList();
        //将分类List传到前段页面
        mav.addObject("categoryList",respCategoryVos);
        //转发首站页面
        mav.setViewName("home/index");
        return mav;
    }
}
